import Vue from 'vue'
import Vuex from 'vuex'

//挂载Vuex
Vue.use(Vuex)

//创建VueX对象
const store = new Vuex.Store({
    state: {
        userList: [
            {
                headImg: "",
                name: "我",
                id: 0,
            },
        ],
        uploadID: 0,
        msgIDtemp: 0,
        msgTypeList: [
            '文本',
            '时间',
            '转账',
            '红包',
            '领取红包'
        ],
        messages: [
            {
                msgID: 0,
                userID: 0,
                type: "文本",
                info: "请输入信息",
                info1: "",
                receiveState: 2
            }
        ],
        deviceOption:{
            width:1,
            height:2
        },
        dialogueType: "single",
        groupName: "相亲相爱一家人",
        groupSize: 20,
        currentTime: ""
    },
    mutations: {
        initTime(state){
            let t=new Date()
            state.currentTime=t;
        },
        addUser(state) {
            let ycyNum = '';
            if (state.userList.length > 1)
                ycyNum = state.userList.length + "号"
            state.userList.push({
                name: "杨超越" + ycyNum,
                id: state.userList.length,
                headImg:""
            })
        },
        EditUploadID(state, id) {
            state.uploadID = id
        },
        addMessage(state) {
            state.messages.push({
                userID: 0,
                msgID: ++state.msgIDtemp,
                info: "明天到你家吃饭",
                type: "文本",
                receiveState:0
            })
        },
        delMessage(state, id) {
            state.messages.forEach((item, index) => {
                if (item.msgID == id) {
                    state.messages.splice(index, 1)
                }
            })
        },
        wipeUser(state) {
            state.userList = state.userList.slice(0, 2)
            console.log(state.userList);

        }
    },
    getters: {
        getOwners(state) {
            return function (id) {
                let arr =[] 
                state.userList.forEach(item => {
                    if (item.id != id) arr.push(item)
                })
                return arr
            }

        }
    }
})

export default store